/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */
{#
  Adapted from:
  https://github.com/open-telemetry/semantic-conventions-java/blob/main/buildscripts/templates/SemanticAttributes.java.j2
  for opentelemetry-cpp

  For doc on the template syntax:
  https://jinja.palletsprojects.com/en/3.0.x/

  For doc on the semantic convention:
  https://github.com/open-telemetry/build-tools/tree/main/semantic-conventions
#}
{%- macro to_cpp_return_type(type) -%}
  {%- if type == "string" -%}
    char *
  {%- elif type == "string[]" -%}
    char *[]
  {%- elif type == "boolean" -%}
    bool
  {%- elif type == "int" -%}
    int
  {%- elif type == "double" -%}
    double
  {%- else -%}
    {{type}}
  {%- endif -%}
{%- endmacro %}
{%- macro print_value(type, value) -%}
  {{ "\"" if type == "char *"}}{{value}}{{ "\"" if type == "char *"}}
{%- endmacro %}
{%- macro upFirst(text) -%}
  {{ text[0]|upper}}{{text[1:] }}
{%- endmacro %}
{%- macro lowerFirst(text) -%}
  {{ text[0]|lower}}{{text[1:] }}
{%- endmacro %}

/*
  DO NOT EDIT, this is an Auto-generated file
  from buildscripts/semantic-convention{{template}}
*/

#pragma once

#include "opentelemetry/common/macros.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
{{namespace_open}}

namespace {{class}}
{
/**
 * The URL of the OpenTelemetry schema for these keys and values.
 */
static constexpr const char *kSchemaUrl = "{{schemaUrl}}";
  {%- for attribute in attributes if attribute.is_local and not attribute.ref %}

/**
 * {{attribute.brief | render_markdown(code="{{@code {0}}}", paragraph="{0}")}}
  {%- if attribute.note %}
 *
 * <p>Notes:
  <ul> {{attribute.note | render_markdown(code="{{@code {0}}}", paragraph="<li>{0}</li>", list="{0}")}} </ul>
  {%- endif %}
{%- if (attribute.deprecated) %}
 *
 * @deprecated {{attribute.brief | to_doc_brief}}.
  {%- endif %}
 */
  {%- if (attribute.deprecated) %}
OPENTELEMETRY_DEPRECATED
  {%- endif %}
static constexpr const char *k{{attribute.fqn | to_camelcase(True)}} = "{{attribute.fqn}}";
{%- endfor %}

// Enum definitions
{%- for attribute in attributes if attribute.is_local and not attribute.ref %}
{%- if attribute.is_enum %}
{%- set enum_name = attribute.fqn | to_camelcase(True) ~ "Values" %}
{%- set type = to_cpp_return_type(attribute.attr_type.enum_type) %}
namespace {{enum_name}}
{
  {%- for member in attribute.attr_type.members %}
  /** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
  static constexpr const {{ type }} k{{ member.member_id | to_camelcase(True) }} = {{ print_value(type, member.value) }};
  {%- endfor %}
}
{% endif %}
{%- endfor %}

{#
  {%- if class == "SemanticAttributes" %}
  // Manually defined and not YET in the YAML
  /**
   * The name of an event describing an exception.
   *
   * <p>Typically an event with that name should not be manually created. Instead {@link
   * io.opentelemetry.api.trace.Span#recordException(Throwable)} should be used.
   */
  static constexpr const char *EXCEPTION_EVENT_NAME = "exception";

  {% endif %}
#}

}  // namespace {{class}}
{{namespace_close}}
OPENTELEMETRY_END_NAMESPACE

